package com.linyu.huawei.simple;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * 查字典
 * 说明：输入一个单词前缀和一个字典，输出包含该前缀的单词
 * 输入：单词前缀 + 字典长度 + 字典
 */
public class ConsultADictionary {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入单词前缀：");
        String preStr = sc.next();
        System.out.print("请输入字典长度：");
        int length = sc.nextInt();
        ArrayList<String> list = new ArrayList<>();
        System.out.println("请依次输入，字典中的单词:");
        for (int i = 0; i < length; i++) {
            list.add(sc.next());
        }

        ArrayList<String> resultList = new ArrayList<>();
        for (String str : list) {
            // 我的思路是，直接截取，对应长度的比较一下
            String substr = str.substring(0,preStr.length());
            System.out.println(substr + "--------");
            if (preStr.equals(substr)){
                resultList.add(str);
            }
        }
        if (resultList.isEmpty()){
            System.out.println("-1");
            return;
        }
        System.out.println(resultList);
    }

}
